import hashlib
import os
import socket
import sys
import requests


def get_python_path():
    """
    获取python路径
    :return:
    """
    host_name = socket.gethostname()
    if host_name == "legend":
        python_path = "/home/legend/WorkSpace/python/water_applets/"
    if host_name == "ecs-364582":
        python_path = "/root/water_applets/"
    else:
        python_path = ""
    return python_path


sys.path.append(get_python_path())
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "water_applets.settings")
django.setup()
from django.utils import timezone
from django.contrib.auth.hashers import make_password
from models.models import ManagerUser


def cal_sha1_string(s):
    return str(hashlib.sha1(s.encode("utf-8")).hexdigest())


def cal_md5_string(s):
    return str(hashlib.md5(s.encode("utf-8")).hexdigest())


def add_admin_user():
    data = {
        "id": 1,
        "username": "admin",
        "password": make_password(cal_sha1_string(cal_md5_string('qianmai2023!@'))),
        "alias": "管理员",
        "email": "qianmai@163.com",
        "mobile": "12345678901",
        "is_active": 1,
        "is_super": 1,
        "create_time": timezone.now(),
        "creator": 0,
        "permission_group": None
    }
    ManagerUser.objects.create(**data)


if __name__ == '__main__':
    add_admin_user()
